/**
 * Copyright (c) 2010-2011 Pierre Labatut
 *
 * This file is part of Space-Chronicles project.
 *
 * Space-Chronicles is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/space-chronicles/>.
 */
package space.game.config;

import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.FilenameFilter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.BackingStoreException;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.Mixer.Info;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
import space.input.FilePlayControler;

/**
 * This modal dialog box is
 * Usage:
 *  GfgFrame.Result result = GfgFrame.run();
 * @author Pierre
 */
class CfgSettingsDialog extends javax.swing.JDialog {

    boolean isDone = false;

    /**
     * Unique constructor.
     * @see CfgFrame.run()
     */
    private CfgSettingsDialog(CfgResult result) {
        GraphicsEnvironment.getLocalGraphicsEnvironment();
        initComponents();
        /**
         * Select the default device
         */
        if (result.getGfxDevice() != null) {
            gfxDeviceCombo.setSelectedItem(result.getGfxDevice());
        } else {
            gfxDeviceCombo.setSelectedItem(
                    GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice());
        }
        if (result.getGfxMode() != null) {
            gfxModeCombo.setSelectedItem(new CfgDisplayMode(result.getGfxMode()));
        }
        gfxFullScreenCombo.setSelectedItem(result.isGfxFullScreen() ? "Yes" : "No");
        if (result.getSfxMixer() != null) {
            sfxDeviceCombo.setSelectedItem(result.getSfxMixer());
        }

        if (result.getCtrlDevice() != null) {
            ctrlControllerCombo.setSelectedItem(result.getCtrlDevice());
        }
        cfgShowPanel.setSelected(result.isCfgShowPanel());
        getRootPane().setDefaultButton(jButton1);
        pack();
    }

    public static CfgResult run() throws CfgCancelApplication {
        final FutureTask<CfgResult> showDialogTask = new FutureTask<CfgResult>(new Callable<CfgResult>() {
            //http://www.felixgers.de/teaching/jogl/fullscreen.html

            public CfgResult call() throws Exception {
                /**
                 * Read user settings, if any. Default values are provided.
                 */
                final CfgPreference userPref = CfgPreference.readPreferences();
                final CfgResult userPrefConfig = userPref.buildResult();
                if (userPrefConfig.isCfgShowPanel() == false
                        && userPrefConfig.isComplete()
                        && Boolean.parseBoolean(System.getProperty("reset")) == false) {
                    return userPrefConfig;
                }
                /**
                 * I use an atomic reference just to share a final reference with the
                 * annonymous Runnable. No multithreading issues.
                 */
                final CfgSettingsDialog dlg = new CfgSettingsDialog(userPrefConfig);
                dlg.setModal(true);
                // Show the dialog in the middle of the screen
                dlg.setLocationRelativeTo(null);
                /**
                 * Run modal
                 */
                dlg.setVisible(true);
                /**
                 * Read dialog state and return a configuration structure
                 */
                final GraphicsDevice gfxDevice =
                        (GraphicsDevice) dlg.gfxDeviceCombo.getSelectedItem();
                final DisplayMode gfxMode =
                        ((CfgDisplayMode) dlg.gfxModeCombo.getSelectedItem()).getMode();
                final boolean gfxFullScreen = "Yes".equals(dlg.gfxFullScreenCombo.getSelectedItem());
                final Mixer.Info mixerInfo = (Info) dlg.sfxDeviceCombo.getSelectedItem();
                final Controller ctrlDevice = (Controller) dlg.ctrlControllerCombo.getSelectedItem();
                final boolean cfgShowPanel = dlg.cfgShowPanel.isSelected();
                final File recordFile = dlg.jRecordLAbel.getText().isEmpty() ? null : new File(
                        dlg.jRecordLAbel.getText());
                final CfgResult result = new CfgResult(gfxDevice, gfxMode,
                        gfxFullScreen, mixerInfo, ctrlDevice, cfgShowPanel, recordFile);

                try {
                    result.buildPreferences().store();
                } catch (BackingStoreException ex) {
                    Logger.getLogger(CfgSettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
                if (dlg.isDone == false) {
                    throw new CfgCancelApplication();
                }
                return result;
            }
        });
        /**
         * Show dialog box and wait for return
         */
        java.awt.EventQueue.invokeLater(showDialogTask);
        try {
            return showDialogTask.get();
        } catch (InterruptedException ex) {
            // The task has been inturepted. 
            throw new CfgCancelApplication(ex);
        } catch (ExecutionException ex) {
            // This is the case when the close button is pressed
            throw new CfgCancelApplication(ex);
        }
    }

    private ComboBoxModel buildGfxDeviceModel() {
        return new DefaultComboBoxModel(
                GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices());
    }

    private ComboBoxModel buildGfxDeviceComboModel() {
        /**
         * I have to decorate DisplayMode to take in charge toString
         * which return the displayed string
         */
        final List<CfgDisplayMode> items = new ArrayList<CfgDisplayMode>();

        final GraphicsDevice gd = (GraphicsDevice) gfxDeviceCombo.getSelectedItem();
        for (DisplayMode mode : gd.getDisplayModes()) {
            items.add(new CfgDisplayMode(mode));
        }
        Collections.sort(items);

        return new DefaultComboBoxModel(items.toArray());
    }

    private ComboBoxModel buildGfxFullScreenComboModel() {
        /**
         * When there is no selection, gfxDeviceCombo is cleared
         */
        if (gfxDeviceCombo.getSelectedObjects().length > 0) {
            final GraphicsDevice gd = (GraphicsDevice) gfxDeviceCombo.getSelectedObjects()[0];
            if (gd.isFullScreenSupported()) {
                return new DefaultComboBoxModel(new String[]{"Yes", "No"});
            } else {
                return new DefaultComboBoxModel(new String[]{"No"});
            }
        }
        return new DefaultComboBoxModel(new String[]{"No"});
    }

    private ComboBoxModel buildSfxDeviceComboModel() {
        return new DefaultComboBoxModel(AudioSystem.getMixerInfo());
    }

    private ComboBoxModel buildCtrlDeviceComboModel() {
        final List<Controller> items = new ArrayList<Controller>();
        final ControllerEnvironment jinput = ControllerEnvironment.getDefaultEnvironment();
        for (Controller ctrl : jinput.getControllers()) {
            if (ctrl.getType().equals(Controller.Type.STICK)) {
                items.add(ctrl);
            }
        }
        final File[] records = new File(".\\record").listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.endsWith(".rec");
            }
        });
        if (records != null) {
            for (File recordFile : records) {
                items.add(new FilePlayControler(recordFile));
            }
        }

        return new DefaultComboBoxModel(items.toArray());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel4 = new javax.swing.JPanel();
        gfxPanel = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        gfxDeviceCombo = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        gfxModeCombo = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        gfxFullScreenCombo = new javax.swing.JComboBox();
        jPanel7 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        sfxDeviceCombo = new javax.swing.JComboBox();
        jPanel8 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        ctrlControllerCombo = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jRecordLAbel = new javax.swing.JTextField();
        jRecordButton = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel6 = new javax.swing.JPanel();
        cfgShowPanel = new javax.swing.JCheckBox();
        jButton1 = new javax.swing.JButton();
        jPanel9 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();

        setTitle("Configuration Settings");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPanel4.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 0, 0, 0));
        jPanel4.setMinimumSize(new java.awt.Dimension(300, 250));
        jPanel4.setLayout(new java.awt.BorderLayout());

        gfxPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Display"));
        gfxPanel.setMinimumSize(new java.awt.Dimension(0, 0));
        gfxPanel.setName(""); // NOI18N

        jLabel9.setText("Device:");
        jLabel9.setPreferredSize(new java.awt.Dimension(70, 14));

        gfxDeviceCombo.setModel(buildGfxDeviceModel());
        gfxDeviceCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gfxDeviceComboActionPerformed(evt);
            }
        });

        jLabel6.setText("Mode:");
        jLabel6.setMaximumSize(new java.awt.Dimension(64, 14));
        jLabel6.setMinimumSize(new java.awt.Dimension(64, 14));
        jLabel6.setPreferredSize(new java.awt.Dimension(70, 14));
        jLabel6.setRequestFocusEnabled(false);

        gfxModeCombo.setModel(buildGfxDeviceComboModel());

        jLabel7.setText("Full Screen:");

        gfxFullScreenCombo.setModel(buildGfxFullScreenComboModel());

        javax.swing.GroupLayout gfxPanelLayout = new javax.swing.GroupLayout(gfxPanel);
        gfxPanel.setLayout(gfxPanelLayout);
        gfxPanelLayout.setHorizontalGroup(
            gfxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gfxPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(gfxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gfxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(gfxDeviceCombo, 0, 365, Short.MAX_VALUE)
                    .addComponent(gfxModeCombo, 0, 365, Short.MAX_VALUE)
                    .addComponent(gfxFullScreenCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        gfxPanelLayout.setVerticalGroup(
            gfxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gfxPanelLayout.createSequentialGroup()
                .addGroup(gfxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(gfxDeviceCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gfxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(gfxModeCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gfxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(gfxFullScreenCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel4.add(gfxPanel, java.awt.BorderLayout.NORTH);

        jPanel7.setLayout(new java.awt.BorderLayout());

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Audio"));
        jPanel3.setMinimumSize(new java.awt.Dimension(400, 60));

        jLabel3.setText("Device:");
        jLabel3.setPreferredSize(new java.awt.Dimension(70, 14));

        sfxDeviceCombo.setModel(buildSfxDeviceComboModel());

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sfxDeviceCombo, 0, 365, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(sfxDeviceCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel7.add(jPanel3, java.awt.BorderLayout.NORTH);

        jPanel8.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 10, 0));
        jPanel8.setLayout(new java.awt.BorderLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Control"));
        jPanel1.setMinimumSize(new java.awt.Dimension(300, 60));

        jLabel2.setText("Joystick:");
        jLabel2.setPreferredSize(new java.awt.Dimension(70, 14));

        ctrlControllerCombo.setModel(buildCtrlDeviceComboModel());

        jLabel1.setText("Record File:");
        jLabel1.setPreferredSize(new java.awt.Dimension(70, 14));

        jRecordLAbel.setEditable(false);

        jRecordButton.setText("...");
        jRecordButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRecordButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ctrlControllerCombo, 0, 365, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRecordLAbel, javax.swing.GroupLayout.PREFERRED_SIZE, 317, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRecordButton, javax.swing.GroupLayout.PREFERRED_SIZE, 42, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ctrlControllerCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRecordButton)
                    .addComponent(jRecordLAbel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel8.add(jPanel1, java.awt.BorderLayout.NORTH);

        jPanel7.add(jPanel8, java.awt.BorderLayout.CENTER);

        jPanel4.add(jPanel7, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);

        jPanel5.setLayout(new java.awt.BorderLayout());
        jPanel5.add(jSeparator1, java.awt.BorderLayout.NORTH);

        jPanel6.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 4, 2, 4));
        jPanel6.setLayout(new java.awt.BorderLayout());

        cfgShowPanel.setText("Show configuration dialog on startup");
        jPanel6.add(cfgShowPanel, java.awt.BorderLayout.WEST);

        jButton1.setLabel("Done");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel6.add(jButton1, java.awt.BorderLayout.EAST);
        jButton1.getAccessibleContext().setAccessibleName("Run");

        jPanel5.add(jPanel6, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel5, java.awt.BorderLayout.SOUTH);

        jPanel9.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 5));
        jPanel9.setLayout(new java.awt.BorderLayout());

        jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/space/game/raptor.png"))); // NOI18N
        jPanel9.add(jLabel8, java.awt.BorderLayout.WEST);

        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jSeparator2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 5, 0, 0));
        jPanel9.add(jSeparator2, java.awt.BorderLayout.EAST);

        getContentPane().add(jPanel9, java.awt.BorderLayout.WEST);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void gfxDeviceComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gfxDeviceComboActionPerformed
        /**
         * Update de display model list
         */
        Object gfxMode = gfxModeCombo.getSelectedItem();
        gfxModeCombo.setModel(buildGfxDeviceComboModel());
        /**
         * Select first item, and fire a selection notification
         */
        if (gfxMode != null) {
            gfxModeCombo.setSelectedItem(gfxMode);
        } else {
            gfxModeCombo.setSelectedIndex(0);
        }

        final Object gfxFullScreen = gfxFullScreenCombo.getSelectedItem();
        gfxFullScreenCombo.setModel(buildGfxFullScreenComboModel());
        gfxFullScreenCombo.setSelectedItem(gfxFullScreen);

    }//GEN-LAST:event_gfxDeviceComboActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        isDone = true;
        setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        isDone = false;
        setVisible(false);
    }//GEN-LAST:event_formWindowClosed

    private void jRecordButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRecordButtonActionPerformed


        final JFileChooser fc = new JFileChooser(".\\record");
        fc.setFileFilter(new FileFilter() {

            @Override
            public boolean accept(File f) {
                return f.getName().endsWith(".rec") || f.isDirectory();
            }

            @Override
            public String getDescription() {
                return "Record (.rec)";
            }
        });

        int returnVal = fc.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            jRecordLAbel.setText(fc.getSelectedFile().toString());
        } else {
            jRecordLAbel.setText("");
        }

    }//GEN-LAST:event_jRecordButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox cfgShowPanel;
    private javax.swing.JComboBox ctrlControllerCombo;
    private javax.swing.JComboBox gfxDeviceCombo;
    private javax.swing.JComboBox gfxFullScreenCombo;
    private javax.swing.JComboBox gfxModeCombo;
    private javax.swing.JPanel gfxPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JButton jRecordButton;
    private javax.swing.JTextField jRecordLAbel;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JComboBox sfxDeviceCombo;
    // End of variables declaration//GEN-END:variables
}
